package com.dingding.service.user.auth.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.common.core.base.daox.ISQLBaseDao;
import com.dingding.common.core.base.daox.impl.CriteriaBaseDaoImpl;
import com.dingding.common.core.beans.City;
import com.dingding.common.core.util.ToolUtil;
import com.dingding.facade.user.dto.order.ReqSyncDriverAuthDTO;
import com.dingding.facade.user.dto.order.ResSyncDriverAuthDTO;
import com.dingding.service.user.auth.dao.ISyncDriverAuthDao;
import com.dingding.service.user.auth.sql.SyncDriverAuthSQL;
/**
 * @Description:同步车主认证状态
 * @author ligang
 * @date 2016年11月22日 下午7:26:33
 * @since 2.5.6
 */
@Component("syncDriverAuthDao")
public class SyncDriverAuthDaoImpl implements ISyncDriverAuthDao{
	Logger log = Logger.getLogger(SyncDriverAuthDaoImpl.class);

	@Resource(name = "criteriaBaseDao")
	CriteriaBaseDaoImpl criteriaBaseDaoImpl;
	
	@Resource(name = "SQLBaseDao")
	private ISQLBaseDao sqlBaseDao;
	
	/**
	 * 
	 * @Description:同步车主认证状态
	 * @author:ligang
	 */
	@Override
	public ResSyncDriverAuthDTO selectSyncDriverAuth(ReqSyncDriverAuthDTO reqSyncDriverAuthDTO) {
		
		try {
			// 根据用户Id获取该用户车主信息
			List<ResSyncDriverAuthDTO> resSyncDriverAuthDTOs = sqlBaseDao.listSqlToCustomBean(ResSyncDriverAuthDTO.class, SyncDriverAuthSQL.SYNC_DRIVER_INFO, reqSyncDriverAuthDTO.getLoginId());
		
			if(resSyncDriverAuthDTOs != null && resSyncDriverAuthDTOs.size() > 0){
				
				ResSyncDriverAuthDTO resSyncDriverAuthDTO = resSyncDriverAuthDTOs.get(0);
				
				// 拼接图片地址
				resSyncDriverAuthDTO.setXszImage(ToolUtil.imageAddress(resSyncDriverAuthDTO.getXszImage()));
				resSyncDriverAuthDTO.setVehicleImage(ToolUtil.imageAddress(resSyncDriverAuthDTO.getVehicleImage()));
				
				//如果车辆审核为通过，则评语不传给客户端
				if(resSyncDriverAuthDTO.getSuvStatus() == 2){
					resSyncDriverAuthDTO.setVehicleDescription(null);
					resSyncDriverAuthDTO.setJszDescription(null);
					resSyncDriverAuthDTO.setXszDescription(null);
				}
				
				return resSyncDriverAuthDTO;
			}
			
		} catch (Exception e) {
			log.error("同步车主认证状态时出现异常   类：" + this.getClass() + " selectSyncDriverAuth()", e);
		}
		
		return null;
	}

	/**
	 * 
	 * @Title: addCity 
	 * @Description: 导入高德Code码与城市名称
	 * @param city 添加城市对象
	 * @author YHQ 
	 * @since V2.5.7
	 * @return boolean    返回类型
	 * 
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public boolean addCity(City city) {
		
		try {
			criteriaBaseDaoImpl.save(city);
			
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return false;
	}

	
}
